﻿using System;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Sustainalytics.LongRunningTaskManager.Interface;
using Newtonsoft.Json;

using Sustainalytics.Entities.ESGRatings;

namespace Sustainalytics.ESGRatings.Tasks.Tests
{
    using Sustainalytics.ESGRatings.Tasks.Models;

    [TestClass]
    public class ESGRatingDataExportTaskTests
    {
        [TestMethod]
        public void StartTest()
        {
            var dto = new TestESGRatingInDto()
            {
                FileName = "test" + DateTime.Now.ToString("s").Replace(":", "_"),
                // regal bengal  c4621c00-af02-4ec6-8399-af1489c9dfc9
                //chevron  6c6845ff-4d9e-4f4d-b920-962af834ef0a
                SelectedCompaniesIds = null, // new List<Guid> { Guid.Parse("6c6845ff-4d9e-4f4d-b920-962af834ef0a") }, // list.Select(x => x.Id).ToList(),
                 //SelectedPeerGroupsIds = peersg.Select(x => x.Id).ToList(), 
                SelectedMatrixId = Guid.Parse("290a624d-a1bf-4298-b91d-2456223923d5"),//def.MatrixId,
                SelectedReferenceUniverseId = Guid.Parse("71f2972e-3153-4f83-ac6e-d82bd676481f"),//def.ReferenceUniverseId, 
                 SelectedComparativeGroup = ComparativeGroupSelection.PeerGroup, 
                 SelectedTemplateType = TemplateTypeSelection.All,
                 SelectedCompanyType = CompanyTypeSelection.All, 
                 AllCompanies = true 
            };

            var json = JsonConvert.SerializeObject(dto);            
            var task = new ESGRatingDataExportTask();
            var context = new LongRunningTaskContext(null, null, json, new System.Threading.CancellationToken());

            var result = task.Start(context);

            Assert.IsNotNull(result);
        }

        [TestMethod]
        public void EsgCompanyReportDownloadTaskTest()
        {

            var rq = new EsgCompanyReportParameters()
            {
                AccountId = Guid.Parse("fafabed8-becd-e411-943f-d89d6764a684"),
                CompanyId = Guid.Parse("5f024979-4dab-4c68-b51e-5dba27f27b64"),
                MatrixId = Guid.Parse("0aaa5eb5-426d-40d3-aec1-f2a01f1d981c"),
                ReferenceUniverseId = Guid.Parse("bdf73a06-0dc7-47df-aa76-2947e30548f6"),

                TemplateType = 0,
                CompanyType = 0,
                ComparativeGroup = 0,
                AccountTier = 1
            };

        

            var json = JsonConvert.SerializeObject(rq);
            var task = new EsgReportDownloadTask();
            var context = new LongRunningTaskContext(null, null, json, new System.Threading.CancellationToken());

            var result = task.Start(context);

            Assert.IsNotNull(result);
        }

        [TestMethod()]
        public void ExecuteEsgComputationRequestTest()
        {
            var dto = new DataContract.ESG.ESGRatingsOptionsDto(){ };
         
            dto.IncludeRatings = true;
            dto.IncludeTopPerformersInfo = true;
            dto.IncludeWeights = true;
            dto.IncludeAggregatedScores = true;
            dto.IncludeAggregatedWeights = true;
            dto.IncludeCompaniesInGroup = true;
            dto.IncludeIndWeightedScores = true;
            dto.RefUnivId = Guid.Parse("71f2972e-3153-4f83-ac6e-d82bd676481f");
            dto.MatrixId = Guid.Parse("290a624d-a1bf-4298-b91d-2456223923d5");


            for (int i = 0; i < 10; i++)
            {
                var result1 = ESGRatingDataExportTask.ExecuteEsgComputationRequest("http://localhost:10280/esgcomputingserv/api/v1/esgcompute", dto, true);

                var result2 = ESGRatingDataExportTask.ExecuteEsgComputationRequest("http://localhost:10280/esgcomputingserv/api/v1/esgcompute", dto, false);
            }
            
            
            Assert.Fail();
        }
    }
}
